package org.veloxbot.api.wrappers;

import org.veloxbot.api.internals.concurrent.Task;

import org.veloxbot.api.methods.Mouse;
import org.veloxbot.api.methods.Camera;

import java.awt.Point;

/**
 * @author Velox
 */
public class VectorTile {

	public static final int NORTH = 0;
	public static final int NORTH_EAST = 45;
	public static final int EAST = 90;
	public static final int SOUTH_EAST = 135;
	public static final int SOUTH = 180;
	public static final int SOUTH_WEST = 225;
	public static final int WEST = 270;
	public static final int NORTH_WEST = 315;

	public static final Point MINIMAP_CENTER = new Point(627, 85);
	public static final int MINIMAP_RADIUS = 72;

	private final int angle;
	private final int distance;

	/**
	 * Creates a vector tile based on the game's compass angle.
	 *
	 * @param angle    The angle at which to focus towards.
	 * @param distance The distance away from the center of the minimap.
	 */
	public VectorTile(final int angle, final int distance) {
		if (distance < 0 || distance > MINIMAP_RADIUS) {
			throw new IllegalArgumentException("Distance out of bounds: [0, 72]");
		}
		this.angle = angle;
		this.distance = distance;
	}

	/**
	 * Gets the focus angle of the VectorTile.
	 *
	 * @return The focus angle of the VectorTile.
	 */
	public int getAngle() {
		return angle;
	}

	/**
	 * Gets the distance from the center of the minimap.
	 *
	 * @return The distance from the center of the minimap.
	 */
	public int getDistance() {
		return distance;
	}

	/**
	 * Gets the point on the minimap relative to the given constructor's parameters.
	 *
	 * @return A point on the minimap relative to the given constructor's parameters.
	 */
	public Point getMapPoint() {
		final double rads = Math.toRadians(angle - 90 + Camera.getCompassAngle());
		return new Point((int) (MINIMAP_CENTER.x - distance * Math.cos(rads)), (int) (MINIMAP_CENTER.y - distance * Math.sin(rads)));
	}

	/**
	 * Clicks the tile on the map.
	 *
	 * @return <t>true</t> if the tile was clicked, and walked to, otherwise <t>false</t>.
	 */
	public boolean clickOnMap() {
		Mouse.click(getMapPoint(), true);
		Task.sleep(1250, 1750);
		return true;
	}
}
